﻿/*
 * 	Copyright 2004-2005 Lookstone Technologies
 *	Written by Jason Seeley
 * 
 *	This file and other files in Lookstone.Common may be freely used, 
 *	modified, and distributed so long as this block remains intact 
 *  in each file it appears in.
 * 
 *	Lookstone Technologies does not warrant that any of this source code 
 *	is free from defect, and will not accept responsibility for any 
 *  failure of software using this library.  By using this library, 
 *  you agree to that Lookstone Technologies and the author of this file 
 *	are not liable for any damages or injuries caused through the use
 *	of this library.
 */

using System;

namespace Lookstone.Data
{
	/// <summary>
	/// Summary description for DataEvent.
	/// </summary>
	public class DataEvent
	{
		private DataEvent()
		{
		}

		public enum EventType
		{
			Add,
			Edit,
			Delete,
			NotSpecified,
		}

		private static event EventHandler<DataChangeEventArgs> DataChanged;

		public static void AddChangeEventHandler(EventHandler<DataChangeEventArgs> handler)
		{
			// example: 
			// DataChangedHandler handler = new DataEvent.DataChangedHandler(myClass.DataChanged)
			// DataEvent.AddChangeEventHandler(handler);

			// Declare method as:
			// private void DataChanged(object sender, DataChangeEventArgs e)
			DataChanged += handler;
		}

		public static void RemoveChangeEventHandler(EventHandler<DataChangeEventArgs> handler)
		{
			DataChanged -= handler;
		}

		public static void InvokeChangeEvent(object sender, DataChangeEventArgs e)
		{
			if (DataChanged != null)
				DataChanged(sender, e);
		}

		public class DataChangeEventArgs : EventArgs
		{
			private EventType _eventType = EventType.NotSpecified;
			private IConnectionContext _context = null;
			private object _object = null;

			public DataChangeEventArgs(EventType eventType, IConnectionContext context, object eventObject)
			{
				_object = eventObject;
				_eventType = eventType;
				_context = context;
			}

			public DataChangeEventArgs(EventType eventType, IConnectionContext context)
			{
				_eventType = eventType;
				_context = context;
			}

			public DataChangeEventArgs(EventType eventType)
			{
				_eventType = eventType;
			}

			public object EventObject
			{
				get { return _object; }
				set { _object = value; }
			}

			public IConnectionContext Context
			{
				get { return _context; }
				set { _context = value; }
			}

			public EventType Action
			{
				get { return _eventType; }
				set { _eventType = value; }
			}
		}
	}
}